<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title><? echo $title ?></title>
    <? require("lib.php"); ?>
</head>
<body>
<div class="content-box"><!-- Start Content Box -->
    <div class="content-box-header">
        <h3><? echo $title ?></h3>
        <div class="clear"></div>
    </div> <!-- End .content-box-header -->
    <div class="content-box-content">
        <?
        switch ($do) {
            case "add":
                add();
                break;
            case "update":
                update($info);
                break;
            case "delete":
                delete($id);
                break;
            default:
                show_info($info);
        }
        ?>
        <? function show_box($row, $iseditmode, $isadd=0){
            global $id, $h, $url, $title, $cate, $baseurl, $option, $arrlang, $lang;
            ?>
            <table width="99%" cellspacing="0" cellpadding="3" class="mbox">
                <tr class="th"><td class="thtitle" width="120" align="right"><? echo $title ?></td>
                    <td><? echo $h->hidden('id', iso($row["id"])); ?></td></tr>
                <tr><td class="l"><?=ROOT_TITLE?></td><td><? echo $h->text('name', $row["name"], 'g') ?></td></tr>
                <tr><td class="l"><?=ROOT_CONTENT?></td><td><? echo $h->textarea('content', $row["content"], 24, 16, 'editor g') ?></td></tr>

                <tr><td class="l"><?=ROOT_KEYWORD?></td><td><? echo $h->text('keyword', $row["keyword"], 'g') ?></td></tr>
                <tr><td class="l"><?=ROOT_DESCRIPTION?></td><td><? echo $h->textarea('description', $row["description"], 24, 4, 'g') ?></td></tr>
                <tr><td class="l"><?=ROOT_LANGUAGE?></td><td><? echo $h->select('language_id', $row["language_id"], $arrlang, 'id', 'name', 'g') ?></td></tr>
                <tr><td class="l"><?=ROOT_CATEGORY?></td><td><? echo $h->select('category_id', $row["category_id"], $cate->get_rows(512), 'id', 'name_'.$lang, 'g') ?></td></tr>
                <? $hide=''; if(! $option['news']['pic']) $hide=' class="hide" '; ?>
                <tr <? echo $hide ?>><td class="l"><?=ROOT_PICTURE?></td><td>
                        <? if(!$isadd)echo '<img src="'.$baseurl.'upload/'.decode($row["pic"]).'" height="72" /><br />'; ?>
                        <? echo $h->cfile('cpic', 'g') ?> <span class="red"> <?=ROOT_CONTACT_ADMIN_FOR_PIC_SIZE_CHANGE?></span>
                    </td></tr>

                <tr><td class="l"><?=ROOT_ORDER?></td><td><? echo $h->text('seq_no', iso($row["seq_no"]), 'gs') ?> <span class="red"> <?=ROOT_HIGHER_NUMBER_IN_FRONT?></span></td></tr>
                <tr><td class="l">&nbsp;</td><td><br><? echo $h->submit('save', '&nbsp; '.ROOT_SAVE.' &nbsp;', $iseditmode==1?'':'hide') ?>&nbsp;&nbsp;<a onClick="history.go(-1)">[ <?=ROOT_CANCEL?> ]</a><br><br></td></tr>
            </table>
        <? } ?>
        <? function show_boxes($result){
            global $url, $page, $pages, $cateid, $s, $lang, $arrlang, $filter, $customer, $h, $code_array;
            $str='<table width="99%" class="mlist"><tr>';  // 搜索
            $str.='<td><form action="'.$url.'.php" method="get"><input type="hidden" name="filter" value="'.$filter.'"/><input placeholder="'.ROOT_SEARCH_BY_NUMBER.'" name="s" class="g" value="'.$s.'" /> &nbsp; <input type="submit" class="button_blue" value=" '.ROOT_SEARCH.' " /></form></td>';
            $str.='<td align="right"><form action="'.$url.'.php" method="get">'.$h->select('filter', $filter, $code_array['score_card'], 'id', 'name_'.$lang, 'g', 'this.form.submit()').'</form></td>';
            $str.='</tr></table>';
            $str.='<table width="99%" cellspacing="0" class="mlist"><tr class="th"><td><strong>'.ROOT_SCORE_CARD_NUMBER.'</strong></td><td><strong>'.ROOT_SCORE_CARD_PASSWORD.'</strong></td><td><strong>'.ROOT_SCORE_CARD_START.'</strong></td><td><strong>'.ROOT_SCORE_CARD_END.'</strong></td><td><strong>'.ROOT_SCORE_CARD_USED.'</strong></td><td><strong>'.ROOT_SCORE_CARD_USED_CUSTOMER.'</strong></td><td><strong>'.ROOT_SCORE_CARD_UPDATED.'</strong></td><td><a href="'.$url.'.php?do=add">[ '.ROOT_ADD.' ]</a>&nbsp;<a href="'.$url.'.php?do=excel">['.ROOT_SCORE_CARD_EXPORT.']</a></td></tr>';
            $count=1;
            foreach( $result as $row)
            {
                $id=$row['id'];
                $number = $row['number'];
                $pwd = $row['pwd'];
                $start_time = $row['start_time'];
                $end_time = $row['end_time'];
                $update_time = $row['update_time'];
                $customer_name = $customer->get_row($row['customer_id']);
                $is_used = '';
                if($row['is_used'] == 1){
                    $is_used = ROOT_SCORE_CARD_UNABLE;
                }
                if($row['is_used'] == 2 || time() >= strtotime($row['end_time'])){
                    $is_used = ROOT_SCORE_CARD_PASTDUE;
                }



                $str.="<tr><td><a href=\"$url.php?do=update&id=".$id."\">".$number."</a></td><td>".$pwd."</td><td>".$start_time."</td><td>".$end_time."</td><td>".$is_used."</td><td>".$customer_name['email']."</td><td>".$update_time."</td><td><a href=\"$url.php?do=update&id=".$id."\">".ROOT_UPDATE."</a> | <a href=\"$url.php?do=delete&id=".$id."\" onClick=\"javascript: return delc();\">".ROOT_DELETE."</a></td></tr>";
                $count++;
            }
            $str.= "</table>";
            echo $str;
            if($count==1) echo "<br>No data now. (".ROOT_NO_DATA."!)";
            echo echo_page($page, $pages, $url.'-'.$cateid.'-p');
        } ?>
        <br class="clear" />
    </div> <!-- End .content-box-content -->
    <br class="clear" />
</div><!-- End .content-box -->
</body>
</html>
